package com.common.help.test14;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Random;

import cn.hutool.core.codec.Base64Decoder;
import cn.hutool.core.codec.Base64Encoder;

public class Mina {

	public static void main(String[] args) {
		try {
			String decode = TokenProcess.getInstance().getToken();
			byte[] bytes = Base64Decoder.decode(decode);
			MessageDigest md5 = MessageDigest.getInstance("MD5");
			md5.update(bytes);
			
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
	}
}

class TokenProcess{
	
	public final static  TokenProcess  instance= new TokenProcess();
	
	private TokenProcess(){}
	
	public static TokenProcess getInstance(){
		return instance;
	}
	
	public String getToken() throws NoSuchAlgorithmException{
	
		String t = System.currentTimeMillis()+ new Random().nextInt(Integer.MAX_VALUE)+"";
		System.out.println(t);
		//加密
		MessageDigest md5 = MessageDigest.getInstance("MD5");
		byte[] token = md5.digest(t.getBytes());
		
		String encode = Base64Encoder.encode(token);
		
		
		System.out.println(encode);
		return encode;
	}
}